<?php
namespace Jtbk\Controller;
use Think\Page;
use Think\Controller;

/**
 * 教学管理控制器
 * @author水月居 <singliang@163.com>
 */
class BeikeController extends Controller {

    /**
     * 集体备课上传
    */
    public function index(){
	    $beike=D('JxBeikePost');
	    $order=array('update_time'=>'desc','subject'=>'desc','grade'=>'desc');
	    $tlist=$beike->order($order)
	    //->field("id,grade,subject,week,abstract,update")
	    ->limit('0,6')->select();
        $this->assign('list', $tlist);
      $this->display();
    }
    /**
     * 集体备课－添加课程
    */
    public function addsubject(){
            $uid=is_login();
       if($uid){
        $my['teacher']=query_user('nickname');
        $my['uid']=$uid;       
       }else{
          $this->error('请先登录再上传',U('/Home/User/login'),3);
          }
          $this->assign(my,$my);      
      if(IS_POST){
        // dump($_POST);
        $subject=D('JxBeike');
        $data=array(
          'subject'=>I('post.subject'),
          'admin'  =>I('post.teacher'),
          'savepath'=>I('post.savepath'),
          'description'=>I('post.description'),
          );
        $subject->create($data);
        $result=$subject->add($date);
             if(!$result ){               
                  $this->error($subject->getError());
                }else{
              
                $this->success('更新成功', Cookie('__forward__'));               
                }   
      }
      $this->assign('sublist',$sublist);
      $this->display();
    }


 

  public function myupload($uid=0){
  	$uid=is_login();
  	$map['uid'] = $uid;
    $list=D('JxBeikePost')->where($map)->select();
    $this->assign('list',$list);
    
     // dump($sublist);
  $this->display();
  }
  /*显示科目集体备课信息 */
    public function listsub($sid=0){
      $sid=I('get.sid'); 
      if(!$sid==0) {
      $subject=D('JxBeike')->find($sid);//获取科目信息
    	$beikepost=D('JxBeikePost');
	    $order=array('grade'=>'desc','update_time'=>'desc');	   
	    $data=$beikepost->field('id,title,teacher,subject,grade,update_time')
	    ->limit(10)->order($order)
	    ->where(array('subject_id'=>$sid))->select();
	    }else{
	    	 $this->error('课程号错误',Cookie('__forward__'),3);
	    }	
      $this->assign('subject', $subject);
      $this->assign('list', $data);
  $this->display();
  }

}